<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/templates/mainLayout.xhtml">

    <ui:define name="title">Tạo mới người dùng</ui:define>
    <ui:define name="idleMonitor">
        <h:form id="monitorForm" prependId="false">
            <p:idleMonitor timeout="#{userBean.conversation.getTimeout()}" onidle="idleDialog.show();" 
                           onactive='window.location = "list.jsf";' rendered="#{!userBean.conversation.isTransient()}"/>

            <p:dialog header="Thông báo" resizable="false" widgetVar="idleDialog" modal="true" width="400">
                <h:outputText value="Phiên làm việc trên trang này đã hết hạn" />
            </p:dialog>
        </h:form>
    </ui:define>
    <ui:define name="content">
        <f:metadata>
            <f:event type="preRenderView" listener="#{userBean.preNewAction()}" />
        </f:metadata>
        <h:form id="mainForm">
            <p:panel header="Tạo mới người dùng">
                <p:messages id="msgs"/>
                <p:toolbar style="margin-bottom: 10px; margin-top: 10px;">
                    <p:toolbarGroup align="left">  
                        <p:commandButton value="Lưu" action="#{userBean.saveAction()}" update="mainForm"/>
                        <p:commandButton value="Hủy" action="#{userBean.cancelAction()}" immediate="true"/>
                        <p:commandButton type="reset" value="Nhập lại"/>
                    </p:toolbarGroup>
                    <p:toolbarGroup align="right">  
                        <p:menuButton value="Chuyển trang">  
                            <p:menuitem value="Trang chủ" url="/home.jsf" />  
                            <p:menuitem value="Danh sách người dùng" url="list.jsf" />
                        </p:menuButton>
                    </p:toolbarGroup>
                </p:toolbar>
                
                <h:panelGrid styleClass="panelGrid" columnClasses="ui-state-default labelCol, ui-widget-content" 
                             columns="2" cellpadding="5" width="100%">
                    <h:outputLabel for="username" style="display: inline; float: right; padding-right: 5px;" value="Tên đăng nhập *" />  
                    <p:inputText value="#{userBean.user.username}" id="username" required="true" label="Tên đăng nhập" maxlength="50"
                                 requiredMessage="Yêu cầu nhập tên đăng nhập"/>
                    
                    <h:outputLabel for="password" style="display: inline; float: right; padding-right: 5px;" value="Mật khẩu *" />  
                    <p:password feedback="false" value="#{userBean.user.password}" id="password" required="true" label="Mật khẩu" 
                                size="30" maxlength="100" requiredMessage="Yêu cầu nhập mật khẩu"/>
                    
                    <h:outputLabel style="display: inline; float: right; padding-right: 5px;" value="Kích hoạt" />  
                    <p:selectBooleanCheckbox value="#{userBean.user.activated}" />
                    
                    <h:outputLabel style="display: inline; float: right; padding-right: 5px;" value="Role" />
                    <p:pickList value="#{userBean.roleModels}" var="role" itemLabel="#{role.name}" 
                                itemValue="#{role}" converter="roleConverter"
                                showSourceControls="true" showTargetControls="true">
                        <f:facet name="sourceCaption">Danh sách quyền</f:facet>  
                        <f:facet name="targetCaption">Quyền đã chọn</f:facet>
                    </p:pickList>
                </h:panelGrid>

                <p:toolbar style="margin-bottom: 10px; margin-top: 10px;">
                    <p:toolbarGroup align="left">  
                        <p:commandButton value="Lưu" action="#{userBean.saveAction()}" update="mainForm"/>
                        <p:commandButton value="Hủy" action="#{userBean.cancelAction()}" immediate="true"/>
                        <p:commandButton type="reset" value="Nhập lại"/>
                    </p:toolbarGroup>
                    <p:toolbarGroup align="right">  
                        <p:menuButton value="Chuyển trang">  
                            <p:menuitem value="Trang chủ" url="/home.jsf" />  
                            <p:menuitem value="Danh sách người dùng" url="list.jsf" />
                        </p:menuButton>
                    </p:toolbarGroup>
                </p:toolbar>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>